package com.door.erp.sevice.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.door.erp.dao.ClientDao;
import com.door.erp.dao.base.GenericDao;
import com.door.erp.model.Client;
import com.door.erp.sevice.ClientLoginService;
import com.door.erp.sevice.base.GenericServiceImpl;

@Service(value="clientLoginService")
public class ClientLoginServiceImp extends GenericServiceImpl<Client, Long> implements
ClientLoginService {
	
	
	@Resource(name="clientDao", type=ClientDao.class)
	private ClientDao clientDao;
	
	@Override
	public GenericDao<Client, Long> getDao() {
		// TODO Auto-generated method stub
		return clientDao;
	}

	@Override
	public boolean validateClientLogin(String phone , String pwd) {
		boolean isLogin = false;
		Client client = this.getClientByAccount(phone, pwd);
		if(client == null ){
			isLogin = false;
		}else{
			isLogin = true;
		}
		return isLogin;
	}
	
	public Client getClientByAccount(String phone,String pwd){
		Map<String,Object> params = new HashMap<String,Object>();
		params.put("phone", phone);
		params.put("pwd", pwd);
		List<Client> list = this.getAll(params);
		if(list.size()>0){
			return list.get(0);
		}else{
			return null;
		}
	}

}
